<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>查看</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../res/layui/css/layui.css">
    <link rel="stylesheet" href="../../res/css/bootstrap.min.css">
    <script src="../../res/js/jquery-3.1.1.min.js" charset="utf-8"></script>
    <script src="../../res/js/Tools.js"></script>
    <script src="../../res/layui/layui.js"></script>
    <script type="text/javascript" src="../../res/js/login_common.js"></script>
    <style>
        .layui-form-label{
            width: 100px;
        }

        .layui-table td{
            padding:28px;
            text-align:center;
            font-size: 14px;
        }

        .cu{
            font-weight: bolder;
        }

    </style>

    <script type="text/javascript">
        //全局同步
        $.ajaxSetup({
            async: false
        });
    </script>

    <script type="text/html" id="suggest">
        <form class="layui-form" action="" id="inputForm" >
            <div class="layui-form-item">
                <label class="layui-form-label">建议</label>
                <div class="layui-input-block">
                    <!--<input type="text" name="resultExp" id ="resultExp" lay-verify="required" placeholder="请输入实施情况" autocomplete="off" class="layui-input" >-->
                    <textarea name="exp" id ="exp" lay-verify="required" placeholder="请输入您的意见和建议" class="layui-textarea"></textarea>
                    <input type="text" name="readTime" id ="readTime" readonly="readonly" placeholder="查看时间" autocomplete="off" class="layui-input" hidden>
                    <input type="text" name="athleteId" id ="athleteId" readonly="readonly" placeholder="运动员ID" autocomplete="off" class="layui-input" hidden>
                    <input type="text" name="athleteName" id ="athleteName" readonly="readonly" placeholder="运动员姓名" autocomplete="off" class="layui-input" hidden>
                    <input type="text" name="schemeId" id ="schemeId" readonly="readonly" placeholder="方案id" autocomplete="off" class="layui-input" hidden>
                    <input type="text" name="schemeName" id ="schemeName" readonly="readonly" placeholder="方案名称" autocomplete="off" class="layui-input" hidden>
                    <input type="text" name="isRead" id ="isRead" readonly="readonly" placeholder="是否查看" autocomplete="off" class="layui-input" hidden>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" id="testListAction" lay-filter="demo1">立即提交</button>
                </div>
            </div>
        </form>
    </script>

    <script type="text/javascript">
        $(function(){
            var schemeId = getQueryString("schemeId");
            var url = "../../AtsSchemeController/selectByschemeId";
            var data = { schemeId : schemeId };
            $.post(url,data,function(obj){
                $("#creatTime").text(getMyDate(obj.creatTime));
            });

            var urls = "../../AtsSchemeController/selectAthleteName";
            $.post(urls,data,function(obj){
                var athleteName = "";
               for(var i in obj){
                   $("#exps").text(obj[i].exp);
                   athleteName = athleteName+","+obj[i].athleteName ;
               }
               athleteName = athleteName.replace(/^(\s|,)+|(\s|,)+$/g, '');
                $("#athleteNames").text(athleteName);
            });

            var urles = "../../AtsSchemeController/selectExist";
            $.post(urles,data,function(obj){
                for(var i in obj){
                    if(obj[i].auditState==="10"){
                        $("#auditState").text("已申请");
                    }else if(obj[i].auditState==="20"){
                        $("#auditState").text("已同意");
                    }else if(obj[i].auditState==="21"){
                        $("#auditState").text("未同意");
                    }else if(obj[i].auditState==="30"){
                        $("#auditState").text("专家已获知待回复");
                    }else if(obj[i].auditState==="40"){
                        $("#auditState").text("已回复");
                    }
                    $("#expertName").text(obj[i].expertName);
                    $("#results").text(obj[i].results);
                }
            });

        // <a id="file1" class="layui-btn layui-btn-xs layui-btn-normal" target="_blank">下载</a>
            var file1 = getQueryString("file1");
            var file2 = getQueryString("file2");
            var file3 = getQueryString("file3");
            var resultFile = getQueryString("resultFile");
            if(file1 != "null"){
               $("#file1").html("<a href='"+'/hbatsams'+file1+"' class=\"layui-btn layui-btn-xs layui-btn-normal\" target=\"_blank\">下载</a>");
            }
            if(file2 != "null"){
                $("#file2").html("<a href='"+'/hbatsams'+file2+"' class=\"layui-btn layui-btn-xs layui-btn-normal\" target=\"_blank\">下载</a>");
            }

            if(file3 != "null"){
                $("#file3").html("<a href='"+'/hbatsams'+file3+"' class=\"layui-btn layui-btn-xs layui-btn-normal\" target=\"_blank\">下载</a>");
            }
            if(resultFile != "null"){
                $("#resultFile").html("<a href='"+'/hbatsams'+resultFile+"' class=\"layui-btn layui-btn-xs layui-btn-normal\" target=\"_blank\">下载</a>");
            }

            // 获取运动员id和姓名，和方案名称，将是否查看改成是
            var url = "../../User/findSession";
            $.post(url,null,function(obj){
                $("#athleteId").val(obj.clerkId);
                $("#athleteName").val(obj.userName);
                $("#isRead").val("已查看");
            });
            /*$("#athleteId").val("2");
            $("#athleteName").val("王五");*/

            var urleses = "../../AtsSchemeController/atsSchemeAuditSelectBySaId";
            var dataeses = { saId : schemeId };
            $.post(urleses,dataeses,function(obj) {
                for (var i in obj) {
                    $("#auExp").text(obj[i].auExp);
                }
            });

            var urles = "../../AtsSchemeController/selectAthleteName";
            var dataes = { schemeId : schemeId };
            $.post(urles,dataes,function(obj){
               for(var i in obj){
                   if(obj[i].athleteId == $("#athleteId").val()){
                        if(obj[i].exp != null){
                            $("#exp").val(obj[i].exp);
                            $("#exp").attr("readonly","readonly");
                            $("#testListAction").attr("class","layui-btn layui-btn-disabled");
                            $("#testListAction").html("已提交");
                            $("#testListAction").attr("disabled","disabled");
                        }
                   }
               }
            });

        });

        function getMyDate(str){
            var oDate = new Date(str),
                oYear = oDate.getFullYear(),
                oMonth = oDate.getMonth()+1,
                oDay = oDate.getDate(),
                oTime = oYear +"-"+ getzf(oMonth) +"-"+ getzf(oDay);//最后拼接时间
            return oTime;
        };
        //补0操作
        function getzf(num){
            if(parseInt(num) < 10){
                num = '0'+num;
            }
            return num;
        };

        function renderTime(date) {
            var dateee = new Date(date).toJSON();
            return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
        };
    </script>

</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>查看</legend>
</fieldset>

<!--<div class="layui-form-item">
    <label class="layui-form-label">方案ID</label>
    <div class="layui-input-inline">
        <input class="layui-input" readonly="readonly" type="text" name="schemeId" id="schemeIds" required
               lay-verify="required" placeholder="方案ID" autocomplete="off"/>
    </div>
    <label class="layui-form-label">方案名称</label>
    <div class="layui-input-inline">
        <input class="layui-input" readonly="readonly" type="text" name="schemeName" id="schemeName" required
               lay-verify="required" placeholder="方案名称" autocomplete="off"/>
    </div>
    <label class="layui-form-label">方案年度</label>
    <div class="layui-input-inline">
        <input class="layui-input" readonly="readonly" type="text" name="year" id="year" required
               lay-verify="required" placeholder="方案年度" autocomplete="off"/>
    </div>
</div>

<div class="layui-form-item">
    <label class="layui-form-label">方案月份</label>
    <div class="layui-input-inline">
        <input class="layui-input" readonly="readonly" type="text" name="month" id="month" required
               lay-verify="required" placeholder="方案月份" autocomplete="off"/>
    </div>
    <label class="layui-form-label">方案类型</label>
    <div class="layui-input-inline">
        <input class="layui-input" readonly="readonly" type="text" name="schemeType" id="schemeType" required
               lay-verify="required" placeholder="方案类型" autocomplete="off"/>
    </div>
</div>

<div class="layui-form-item">
    <label class="layui-form-label">附件1地址</label>
    <div class="layui-input-block">
        <input type="text" name="file1" readonly="readonly" id ="file1" lay-verify="required" placeholder="附件1地址" autocomplete="off" class="layui-input" >
    </div>
</div>

<div class="layui-form-item">
    <label class="layui-form-label">附件2地址</label>
    <div class="layui-input-block">
        <input type="text" name="file2" readonly="readonly" id ="file2" lay-verify="required" placeholder="附件2地址" autocomplete="off" class="layui-input" >
    </div>
</div>

<div class="layui-form-item">
    <label class="layui-form-label">附件3地址</label>
    <div class="layui-input-block">
        <input type="text" name="file3" readonly="readonly" id ="file3" lay-verify="required" placeholder="附件3地址" autocomplete="off" class="layui-input" >
    </div>
</div>

<div class="layui-form-item">
    <label class="layui-form-label">教练员ID</label>
    <div class="layui-input-inline">
        <input class="layui-input" readonly="readonly" type="text" name="coachId" id="coachId" required
               lay-verify="required" placeholder="教练员ID" autocomplete="off"/>
    </div>
    <label class="layui-form-label">教练员姓名</label>
    <div class="layui-input-inline">
        <input class="layui-input" readonly="readonly" type="text" name="coachName" id="coachName" required
               lay-verify="required" placeholder="教练员姓名" autocomplete="off"/>
    </div>
    <label class="layui-form-label">反馈时间</label>
    <div class="layui-input-inline">
        <input class="layui-input" readonly="readonly" type="text" name="resultTime" id="resultTime" required
               lay-verify="required" placeholder="反馈时间" autocomplete="off"/>
    </div>
</div>

<div class="layui-form-item">
    <label class="layui-form-label">实施情况</label>
    <div class="layui-input-block">
        <textarea id="resultExp" name="resultExp" readonly="readonly" class="layui-textarea"></textarea>
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">实施效果</label>
    <div class="layui-input-block">
        <textarea id="resultEffect" name="resultEffect" readonly="readonly" class="layui-textarea"></textarea>
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">实施附件</label>
    <div class="layui-input-block">
        <input type="text" name="resultFile" readonly="readonly" id ="resultFile" lay-verify="required" placeholder="实施附件" autocomplete="off" class="layui-input" >
    </div>
</div>
<div><form class="layui-form" action="" id="inputForm" >
    <div class="layui-form-item">
        <label class="layui-form-label">建议</label>
        <div class="layui-input-block">
            &lt;!&ndash;<input type="text" name="resultExp" id ="resultExp" lay-verify="required" placeholder="请输入实施情况" autocomplete="off" class="layui-input" >&ndash;&gt;
            <textarea name="exp" id ="exp" lay-verify="required" placeholder="请输入您的意见和建议" class="layui-textarea"></textarea>
            <input type="text" name="readTime" id ="readTime" readonly="readonly" placeholder="查看时间" autocomplete="off" class="layui-input" >
            <input type="text" name="athleteId" id ="athleteId" readonly="readonly" placeholder="运动员ID" autocomplete="off" class="layui-input" >
            <input type="text" name="athleteName" id ="athleteName" readonly="readonly" placeholder="运动员姓名" autocomplete="off" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" id="testListAction" lay-filter="demo1">立即提交</button>
            <button type="close" class="layui-btn layui-btn-primary" onclick="closeWindow()">关闭</button>
        </div>
    </div>
</form></div>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>无边框表格</legend>
</fieldset>-->

<table class="layui-table" lay-even="" lay-skin="nob">
    <colgroup>
        <col width="150">
        <col width="300">
        <col width="170">
        <col width="300">
    </colgroup>
    <thead>
    <tr>
        <td class="cu">方案名称</td>
        <td id="schemeNames"></td>
        <td class="cu">方案类型</td>
        <td id="schemeType"></td>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td class="cu">教练员</td>
        <td id="coachName"></td>
        <td class="cu">创建时间</td>
        <td id="creatTime"></td>
    </tr>
    <tr>
        <td class="cu">运动员</td>
        <td id="athleteNames"></td>
        <td class="cu">创建人</td>
        <td id="coachNames"></td>
    </tr>
    <tr>
        <td class="cu">实施情况</td>
        <td id="resultExp"></td>
        <td class="cu">实施效果</td>
        <td id="resultEffect"></td>
    </tr>
    <tr>
        <td class="cu">反馈时间</td>
        <td id="resultTime"></td>
        <td class="cu">申请咨询状态</td>
        <td id="auditState"></td>
    </tr>
    <tr>
        <td class="cu">审核意见</td>
        <td id="auExp"></td>
    </tr>
    <tr>
        <td class="cu">专家</td>
        <td id="expertName"></td>
        <td class="cu">专家咨询结果</td>
        <td id="results"></td>
    </tr>
    <tr>
        <td class="cu">附件一</td>
        <td id="file1"></td>
        <td class="cu">附件二</td>
        <td id="file2"></td>
    </tr>
    <tr>
        <td class="cu">附件三</td>
        <td id="file3"></td>
        <td class="cu">实施附件</td>
        <td id="resultFile"></td>
    </tr>
    <tr>
        <td class="cu">运动员建议</td>
        <td id="exps"></td>
        <td class="cu">  </td>
        <td></td>
    </tr>
    </tbody>
</table>
<!--建议-->
<div id="suggests">
    <script type="text/javascript">
        var suggest = getQueryString("suggest");
        if(suggest == "true"){
            $("#suggests").append($("#suggest").html());
        }
    </script>
</div>
<script type="text/javascript">
    /**
     * 关闭当前弹出层
     */
    function closeWindow(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }

</script>

<script>
    layui.use(['form', 'layedit', 'layer', 'laydate','tree','util','upload'], function(){
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , tree = layui.tree
            ,util = layui.util
            ,upload = layui.upload;

        form.render();
        laydate.render({
            elem: '#readTime',
            value: new Date(),
            type: 'datetime'
        });

        /*var file1 = $("#file1").attr("href");
        alert(file1);*/

        /*var readTime = $("#readTime").val();
        var isRead = "已查看";
        var schemeId = getQueryString("schemeId");
        var data = { readTime : readTime, isRead : isRead, schemeId :schemeId};
        var url = "../../AtsSchemeController/updateAtsSchemeAthlete";
        $.post(url,data);*/

        //自定义验证规则
        form.verify({
            files: function(value){
                if(value.length == 0){
                    return '必须上传实施附件';
                }
            }

            ,content: function(value){
                layedit.sync(editIndex);
            }
        });


        var i = 0;
        //监听提交
        form.on('submit(demo1)', function(data){
            var url = "../../AtsSchemeController/updateAtsSchemeAthletes";
            var formData = new FormData(document.getElementById("inputForm"));
            //传输路径
            $.ajax({
                url:url,
                type:"post", // 传输类型
                data:formData, // 数据
                async:false, // 全局同步
                processData:false,
                contentType:false,
                dataType:"json",
                success:function(obj){
                    // alert("操作成功");
                    //     layer.alert("操作成功");
                    layer.msg(obj.msg,{
                        icon:1,
                        time:1000,
                    },function(){
                        var indexs = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(indexs);
                    });
                    return false ;


                },
                error:function(e){
                    layer.msg(obj.msg,{
                        icon:1,
                        time:1000,
                    },function(){
                        var indexs = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(indexs);
                    });
                    return false ;
                }
            });

            return false ;


        });


    });

</script>
</body>
</html>